package com.eascs.frequency.service.impl;

import javax.inject.Inject;

import org.springframework.stereotype.Component;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.frequency.service.FrequencyDataService;
import com.eascs.frequency.service.FrequencyService;

@Component
public class FrequencyServiceImpl implements FrequencyService{
	private static final Logger logger = LoggerFactory.getLogger(FrequencyServiceImpl.class);
	@Inject
	private FrequencyDataService frequencyDataService;
	@Override
	public long frequency(String key, String type, String biz, long value) {
		long ret = frequencyDataService.get(key, type, biz);
		logger.debug("================cached get:"+ret);
		ret++;
		
		if("loop".equals(type)&&ret>value){
			ret = 0;
		}
		ret = frequencyDataService.update(key, type, biz, ret);
		return ret;
	}
	@Override
	public long get(String key, String type, String biz) {
		return frequencyDataService.get(key, type, biz);
	}
	@Override
	public long toZero(String key, String type, String biz) {
		return frequencyDataService.toZero(key, type, biz);
	}


}
